<template>
  <div class="census-manage">
    <basic-container>
      <avue-crud
        :table-loading="loading"
        ref="crud"
        :option="option"
        :data="data"
        :page.sync="page"
        :search.sync="search"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="onLoad"
        @search-change="searchChange"
        v-model="item"
      >
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { getProjectgaugeincludeuser } from "@/api/census/user";
export default {
  name: "reportGrid",
  components: {},
  data() {
    let _this = this;
    return {
      teamReport: false,
      item: {},
      user: {},
      search: {},
      answerData: [],
      sampleParams: {},
      projectId: "",
      answerDetailDialogView: false,
      selectionList: [],
      promote: true,
      page: {
        pageSize: 10,
      },
      option: {
        // addBtnText: '添加类别',
        delBtnText: "删除",
        excelBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        border: true,
        menu: false,
        selection: false,
        index: true,
        expandLevel: 3,
        headerAlign: "left",
        align: "left",
        tree: false,
        addBtn: false,
        labelWidth: 160,
        menuWidth: 100,
        column: [
          {
            label: "学号",
            prop: "userCode",
            overHidden: true,
            width: 150,
            search: true,
            searchLabelWidth: 100,
          },
          {
            label: "姓名",
            prop: "includeName",
            width: 150,
            overHidden: true,
            search: true,
            searchLabelWidth: 100,
          },
          {
            label: "性别",
            width: 150,
            overHidden: true,
            prop: "sex",
            search: true,
            type: "select",
            searchValue: _this.$route.query.sex || "",
            dicData: [
              {
                label: "男",
                value: "1",
              },
              {
                label: "女",
                value: "2",
              },
            ],
          },
          {
            label: "学校",
            overHidden: true,
            prop: "tenantName",
          },
          {
            label: "年级",
            width: 150,
            search: true,
            searchValue: _this.$route.query.gradeName || "",
            overHidden: true,
            searchMultiple: true,
            type: "select",
            prop: "gradeName",
            props: {
              label: "gradeName",
              value: "gradeName",
            },
            dicUrl: `/api/blade-system/grade/list`,
          },
          {
            label: "班级",
            overHidden: true,
            width: 150,
            prop: "className",
            search: true,
            searchLabelWidth: 100,
          },
          {
            label: "测试项目",
            width: 150,
            overHidden: true,
            searchLabelWidth: 100,
            // searchValue: _this.$route.query.projectId || "",
            prop: "projectName",
            search: true,
            // type: "select",
            // dicUrl: `/api/blade-measure/measure/project/list?tenantId=${_this.$route.query.tenantId}&current=1&size=100`,
            // props: {
            //   label: "projectName",
            //   value: "projectId",
            // },
          },
          {
            label: "项目发布时间",
            overHidden: true,
            width: 150,
            prop: "createdAt",
          },
        ],
      },
      data: [],
      loading: true,
      params: {},
    };
  },
  computed: {
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.projectId);
      });
      return ids.join(",");
    },
  },
  created() {},
  mounted() {
    let guidanceNote = ""; // 请求后台返回的内容字符串
    this.str = this.escapeStringHTML(guidanceNote);
    let params = Object.assign({}, this.$route.query);
    this.onLoad(this.page, params);
  },
  methods: {
    async onLoad(page = this.page, params = {}) {
      //获取年级等参数
      if (this.$route.query.projectId) {
        params.projectId = this.$route.query.projectId;
      }
      params.tenantId = this.$route.query.tenantId;
      params.testFlag = "N";
      if (params.gradeName) {
        if (Array.isArray(params.gradeName)) {
          params.gradeName = params.gradeName.join(",");
        } else {
          params.gradeName = params.gradeName;
        }
        // delete params.gradeName;
      } else {
        if (this.$route.query.gradeName)
          params.gradeName = this.$route.query.gradeName;
      }
      if (this.$route.query.projectId) {
        params.projectId = this.$route.query.projectId;
      }

      console.log(params);
      const {
        data: { data },
      } = await getProjectgaugeincludeuser(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      );
      this.loading = false;
      this.data = data.records;
      this.data.map((item) => {
        item.level = item.level + "";
      });
      this.page.total = data.total;
      this.loading = false;
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad();
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad();
    },
    async searchChange(params, done) {
      await this.onLoad(this.page, params);
      done();
    },
    handleDown() {
      this.$router.push({
        name: "异常详情",
        query: {
          projectId: this.$route.query.projectId,
          tenantId: this.$route.query.tenantId,
        },
      });
    },
    getToDetail(row) {
      this.$router.push({
        name: "个人档案",
        query: {
          userId: row.userId,
        },
      });
    },
    escapeStringHTML(str) {
      //把实体格式字符串转义成HTML格式的字符串
      str = str.replace(/&lt;/g, "<");
      str = str.replace(/&gt;/g, ">");
      return str;
    },
  },
};
</script>

<style lang="scss" scoped>
.census-manage {
  .container {
    height: 70vh;
    overflow-y: auto;
  }
  .dialogInfoCss {
    overflow-y: hidden;
    margin-top: -50px;
    // margin-bottom: 40px;
  }
}
</style>
